/*
 * Copyright 2018 - 2050 zyp.All Rights Reserved.
 *
 */
package com.zyp.common.message.manager.impl;

import com.alibaba.fastjson.JSON;
import com.zyp.common.message.manager.PushMessageManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 推送消息记录 <br />
 * @createTime 2018-11-17 10:33:47
 * @author dev-center
 */

@Service
@Slf4j
public class PushMessageManagerImpl implements PushMessageManager, RabbitTemplate.ConfirmCallback{

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void get() {
        Map param = new HashMap(2);
        param.put("userId", "1001");
        param.put("userName", "王丽");
        rabbitTemplate.setMandatory(true);
        rabbitTemplate.setConfirmCallback(this);
        rabbitTemplate.convertAndSend("order-message-exchange",
                "order-message-queue-key",
                JSON.toJSONString(param),
                new ExpirationMessagePostProcessor(30000L),
        new CorrelationData(JSON.toJSONString(param)));
    }

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        log.info("confirm logs : {}", correlationData);
    }
}
